package com.example.mybatisplus.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.mybatisplus.model.domain.BuildingManagement;
import com.example.mybatisplus.mapper.BuildingManagementMapper;
import com.example.mybatisplus.model.dto.PageDTO;
import com.example.mybatisplus.service.BuildingManagementService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import com.example.mybatisplus.mapper.BedManagmentMapper;
import java.util.List;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ablbb
 * @since 2024-07-19
 */
@Service
public class BuildingManagementServiceImpl extends ServiceImpl<BuildingManagementMapper, BuildingManagement> implements BuildingManagementService {


    @Override
    public Page<BuildingManagement> pageList(BuildingManagement buildingManagement, PageDTO dto){
        QueryWrapper<BuildingManagement> wrapper = new QueryWrapper<>();
        if (StringUtils.isNotBlank(buildingManagement.getBuildingId())){
            wrapper.like("building_id",buildingManagement);
        }
        if (buildingManagement.getTotalFloor() != null) {
            int total_floor = buildingManagement.getTotalFloor();
            wrapper.like("total_floor", total_floor);  // 使用整数进行条件操作
        }
        if (StringUtils.isNotBlank(buildingManagement.getType())){
            wrapper.like("type",buildingManagement);
        }
        if (buildingManagement.getTotalRoom() != null) {
            int total_room = buildingManagement.getTotalRoom();
            wrapper.like("total_room", total_room);  // 使用整数进行条件操作
        }
        if (buildingManagement.getTotalBed() != null) {
            int total_bed = buildingManagement.getTotalBed();
            wrapper.like("total_bed", total_bed);  // 使用整数进行条件操作
        }
        Page<BuildingManagement> page =new Page<>();
        page.setCurrent(dto.getPageNo()).setSize(dto.getPageSize());
        baseMapper.selectPage(page,wrapper);
        return page;
    }

    @Override
    public void importbuilding(MultipartFile file) throws IOException {
        Workbook workbook = new HSSFWorkbook(file.getInputStream());
    }

    @Override
    public void updateTotalRoomsForBuilding(String buildingId) {

    }


    /*@Transactional
    public void updateTotalRoomsForBuilding(String buildingId) {
        Integer totalRoom = baseMapper.calculateTotalRoomsForBuilding(buildingId);
        baseMapper.updateTotalRoomsForBuilding(buildingId, totalRoom);
    }*/

    @Override
    public int getTotalRoomsForBuilding(String buildingId) {
        // return baseMapper.(buildingId);
//        return getTotalRoomsForBuilding(buildingId);
        return 0;
    }
}
